"""
Multiprocessing allows the execution of multiple processes concurrently
Each process has its own memory space and runs independently
It is useful for CPU-bound tasks or when parallelism is required
"""

import multiprocessing
import time

# Define a function to be executed in a process
def process_function(name):
    print(f"Process {name} started")
    time.sleep(2)  # Simulate some work
    print(f"Process {name} completed")

# Create and start multiple processes
processes = [
    multiprocessing.Process(target=process_function, args=("Process 1",)),
    multiprocessing.Process(target=process_function, args=("Process 2",)),
    multiprocessing.Process(target=process_function, args=("Process 3",))
]

for process in processes:
    process.start()

# Wait for all processes to complete
for process in processes:
    process.join()

print("All processes completed")
